<%-- 
    Document   : ManageAdmin
    Created on : Nov 2, 2011, 12:01:23 AM
    Author     : Mr-aUgust
--%>

<%@page pageEncoding="UTF-8"%>
<%@ page session="true" import="java.util.Collection, DAL.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>East2West Tours and Travels</title>
        <script src="../js/jqueryvalidate.js" type="text/javascript"></script>
        <script src="../js/jquery.validate.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function() {
            $("#formadmin").validate
                ({
                    rules:{
                        username:{ required: true,minlength: 5},
                        password:{ required: true,minlength: 8},
                        confirm_password:{ required: true,equalTo: "#password"},
                        fullname:{ required: true,minlength: 10},
                        email:{ required: true,email: true},
                        address:{ required: true,minlength: 15},
                        phone:{ required: true,minlength: 10,digits: true}
                    },
                    messages: {
                        username:{required:"*",minlength: "Username at least 5 characters"},
                        password:{ required:"*",minlength: "Password at least 8 characters"},
                        confirm_password:{ required:"*",equalTo: "Please enter the same password as above"},
                        fullname:{ required:"*",minlength: "Full name at least 10 characters"},
                        email:{ required:"*",email: "Please enter a valid email address" },
                        address:{ required:"*",minlength: "Full name at least 15 characters"},
                        phone:{ required:"*",minlength: "Phone number at least 10 digits" , digits: "Please enter only digits"}
                        }            
                });   
                
            });
            $(document).ready(function() {
            $("#formadminEdit").validate
                ({
                    rules:{
                        username:{ required: true,minlength: 5},                       
                        fullname:{ required: true,minlength: 10},
                        email:{ required: true,email: true},
                        address:{ required: true,minlength: 15},
                        phone:{ required: true,minlength: 10,digits: true}
                    },
                    messages: {
                        username:{required:"*",minlength: "Username at least 5 characters"},
                        fullname:{ required:"*",minlength: "Full name at least 10 characters"},
                        email:{ required:"*",email: "Please enter a valid email address" },
                        address:{ required:"*",minlength: "Full name at least 15 characters"},
                        phone:{ required:"*",minlength: "Phone number at least 10 digits" , digits: "Please enter only digits"}
                    }            
                });   
                
            });
         </script>
       <style type="text/css">
            .khunvien
           {
                width:630px;
                height:500px;
                background-color:#f0f3ec;
                margin-top:0px;
           } 
           #Table
            {
            border:1px solid green;
            }
            th
            {
             border:1px solid green;
            background-color:green;
            color:white;
            }
            .td
            {
             border:1px solid green;
            }
            .font
            {
                font-family:"Times New Roman", Times, serif;
                font-size:x-large;
                font-weight:bold;
                width:200px;
                margin-left:auto;
                margin-right:auto;
                color:#0707e7;
            }
            #reset
            {
            width:120px;
            }
        </style>
    </head>
    <body>
        <div class="khunvien">
            <%
                //session.removeAttribute("status");
                session.removeAttribute("statusH");
                String status="",user="",fullname="",email="",address="",phone="";
                String role="";
                if(session.getAttribute("status")==null)
                    {
            %>
            <form action="../ControllerAdmin" method="post" name="formadmin" id="formadmin">
               <table class="table" border="0" cellpadding="2" cellspacing="2" width="630px" >
                     <tr>
                         <td></td>
                        <td align="left" class="font">Create User</td> 
                     </tr>   
                     <tr>
                         <td colspan="2" height="20px"></td>
                     </tr>
                    <tr>
                        <td width="30px">User Name:</td>
                        <td width="100px" style="color:red;"><input type="text" name="username"   maxlength="15" size="30" /></td>
                    </tr>    
                    <tr>
                        <td>PassWord:</td>
                        <td style="color:red;"><input type="password" id="password" name="password" maxlength="15" size="30" /></td>
                    </tr>
                    <tr>
                        <td>Comfirm Pass:</td>
                        <td style="color:red;"><input type="password" id="confirm_password" name="confirm_password" maxlength="50" size="30" /></td>
                    </tr>
                    <tr>
                        <td>Full Name:</td>
                        <td style="color:red;"><input type="text" id="fullname" name="fullname" maxlength="50" size="30" /></td>
                    </tr>
                    <tr>
                        <td>Email:</td>
                        <td style="color:red;"><input type="text" name="email" size="30" /></td>
                    </tr>
                    <tr>
                        <td>Address:</td>
                        <td style="color:red;"><textarea rows="3" cols="25" name="address" ></textarea></td>
                    </tr>
                    <tr>
                        <td>Phone:</td>
                        <td style="color:red;"><input type="text" name="phone" maxlength="13" size="30" /></td>
                    </tr>                  
                        <tr>
                            <td>Role</td>
                            <td>
                                <select name="role">
                                    <option value="0">Employee</option>
                                    <option value="1">Admin</option>
                                </select>
                            </td>
                        </tr> 
                      <tr>
                         <td colspan="2" height="20px"></td>
                     </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" name="createAmdmin" value="Create Amdmin"/><input id="reset" type="reset" value="Reset"  /></td>
                    </tr>
                    </table>
                </form>
                <%
                }
                else
                    {
                        user=session.getAttribute("username").toString();
                        fullname=session.getAttribute("fullname").toString();
                        email=session.getAttribute("email").toString();
                        address=session.getAttribute("address").toString();
                        phone=session.getAttribute("phone").toString();
                        role=session.getAttribute("role").toString();
                %>
                
                 <form action="../ControllerAdmin" method="post" name="formadminEdit" id="formadminEdit">
               <table class="table" border="0" cellpadding="2" cellspacing="2" width="500px" >
                     <tr>
                         <td></td>
                        <td align="left" class="font">Edit User</td> 
                     </tr>         
                     <tr>
                         <td colspan="2" height="20px"></td>
                     </tr>
                    <tr>
                        <td width="50px">User Name:</td>
                        <td width="150px" ><input type="hidden" name="username" value="<%=user%>" /><label><%=user%></label></td>
                    </tr>    
                    <tr>
                        <td>Full Name:</td>
                        <td style="color:red;"><input type="text" id="fullname" name="fullname" value="<%=fullname%>" maxlength="50" size="30" /></td>
                    </tr>
                    <tr>
                        <td>Email:</td>
                        <td style="color:red;"><input type="text" name="email" value="<%=email%>" size="30" /></td>
                    </tr>
                    <tr>
                        <td>Address:</td>
                        <td style="color:red;"><textarea rows="3" cols="25" name="address" ><%=address%></textarea></td>
                    </tr>
                    <tr>
                        <td>Phone:</td>
                        <td style="color:red;"><input type="text" name="phone" value="<%=phone%>" maxlength="13" size="30" /></td>
                    </tr>
                        <tr>
                            <td>Role</td>
                            <td>
                                <select name="role">
                                    <%
                                        if(role.equals("1"))
                                            {
                                           %>
                                            <option value="1">Admin</option>
                                            <option value="0">Employee</option>
                                           <%
                                            }
                                            else
                                            {
                                            %>
                                            <option value="0">Employee</option>
                                            <option value="1">Admin</option>
                                            <%
                                            }
                                    %>
                                </select>
                            </td>
                        </tr>
                    <tr>
                        <td align="right">
                            <input  type="submit" name="update" value="Update"/>
                        </td>
                        <td>          
                        <form action="../ControllerAdmin" method="post" name="formreset" id="">
                         <input  type="submit" name="Cancelupdate" value="Cancel Update"/> 
                        </form> 
                     </td>   
                    </tr>
                    </table> 
                </form>
                <%}%>
                
        </div>
       <%
        AdminBean ad=new AdminBean();
        Collection coll=ad.SelectAdmin();
        request.setAttribute("admin",coll);
      %>
       
    <div class="font">List Of User</div>    
    <table width="100%" id="Table">  
        <tr>
            <th>UserName</th>
            <th>FullName</th>
            <th>Email</th>
            <th>Address</th>
            <th>Phone</th>
            <th>Role</th>
            <th>Edit</th>
            <th>Delete</th>
        </tr>
        <pg:paging pageSize="5" url="management.jsp?page=ManageAdmin"  >
        <c:forEach items="${admin}" var="c">
            <pg:item>
        <tr>
            <td class="td">${c.userName}</td>
            <td class="td">${c.fullName}</td>
            <td class="td">${c.email}</td>
            <td class="td">${c.address}</td>
            <td class="td">${c.phone}</td>
            <td class="td">
                <c:if test="${c.role==1}">Admin</c:if> 
                <c:if test="${c.role==0}">Employee</c:if>
            </td>
            <td class="td">
                <form action="../ControllerAdmin" method="post">
                    <input type="hidden" name="username" value="${c.userName}" />
                    <input type="hidden" name="fullname" value="${c.fullName}" />
                    <input type="hidden" name="email" value="${c.email}" />
                    <input type="hidden" name="address" value="${c.address}" />
                    <input type="hidden" name="phone" value="${c.phone}" />
                    <input type="hidden" name="role" value="${c.role}" />
                    <input type="submit" name="edit" value="Edit"/>
               </form>
            </td>
            <td class="td">
                <form action="../ControllerAdmin" method="get" name="daleteAdmin">
                    <input type="hidden" name="username" value="${c.userName}" />
                    <input type="submit" name="delete" value="Delete" OnClick="return confirm('Are you sure you want delete record this?');"/>
                </form>
            </td>
        </tr>
    </pg:item>       
    </c:forEach>
        <pg:index>
          <pg:page><%=thisPage%></pg:page>
        </pg:index>
    </pg:paging>
    </table>
    </body>
</html>

